// pt3.C -- post ta pid going on
void pt3(){
  TFile *f = new TFile(getenv("TMP1"), "UPDATE");
  TTree *etf = (TTree *)f->Get("etf");
  TCut cut = "1 "
    // "&& x_f1>=-17.&&x_f1<=-11. "
    // "&& pdcTaUWire[1][0]>=-15.&&pdcTaUWire[1][0]<=-11. "
    // "&& pid.beta0()>0.6&&pid.beta0()<0.7 "
    "&& fabs(globalTracker.dx2())<4. "
    "&& sqrt((pTAU[0]+7.)*(pTAU[0]+7.)+(pTAU[1]+1.5)*(pTAU[1]+1.5))<25. " // within TA
    "&& fabs(pT1[0]+6.2)<24. && fabs(pT1[1]+3.2)<24. " // within tstop
    "&& z0c>=19.5&&z0c<=20.5 "
  ;
  TCut a1 = "aoz0c>1.9 && aoz0c<1.97";
  TCut a2 = "aoz0c>1.97 && aoz0c<2.02";
  TCut a3 = "aoz0c>2.02 && aoz0c<2.075";
  TCut a4 = "aoz0c>2.075 && aoz0c<2.123";
  TCut a5 = "aoz0c>2.123 && aoz0c<2.2";
  etf->Draw(">>el", cut, "entrylist");
  TEntryList *el = (TEntryList *)f->Get("el");
  etf->SetEntryList(el);

  etf->Draw("z0c:aoz0c>>h1(200, 1.9, 2.2, 200, 16., 25.)");
  etf->Draw("et.tof2:aoz0c>>h2(100, 1.9, 2.2, 150, 60., 80.)");
  etf->Draw("pid.aoz():aoz0c>>h3(100, 1.9, 2.2, 120, 1.9, 2.6)");
  // etf->Draw("et.tof2:et.tof1>>h2(200, 138., 148., 200, 61., 74.)");
  // etf->Draw("pid.beta():pid.beta0()>>h3(200, 0.59, 0.62, 200, 0.51, 0.64)");
  etf->Draw("postMagTrackerX.ang()-globalTracker.GetPostTaTrack().ang():aoz0c>>h4(200, 1.9, 2.2, 200, 10., 20.)");
  etf->Draw("postMagTrackerX.GetHitPos(\"tofwB\"):aoz0c>>h5(200, 1.9, 2.2, 200, -700., 700.)");
  // etf->Draw("postMagTrackerX.GetHitPos(\"tofwB\")>>h6(300, -700., 700.)");
  etf->Draw("pid.aoz()>>h6(250, 1.9, 2.6)");
  // etf->Draw("pid.poz():pid.beta()>>h6(100, 0.55, 0.61, 100, 1319., 1588.)");

  TCanvas *c = new TCanvas("c", "Tstop Statistics", 1680, 1050);
  c->Divide(3,2); char h[64]; TH1 *b;
  for(int i = 0; i < 6; i++){
    sprintf(h, "h%d", i+1); f->GetObject(h,b);
    c->cd(i+1)->SetGrid(); b->Draw("col");
  } // end for

  // c->cd(6);
  // etf->Draw("pid.aoz()>>ha1(250, 1.9, 2.6)", a1, "same");
  // ((TH1F *)f->Get("ha1"))->SetFillColor(1);
  // etf->Draw("pid.aoz()>>ha2(250, 1.9, 2.6)", a2, "same");
  // ((TH1F *)f->Get("ha2"))->SetFillColor(2);
  // etf->Draw("pid.aoz()>>ha3(250, 1.9, 2.6)", a3, "same");
  // ((TH1F *)f->Get("ha3"))->SetFillColor(3);
  // etf->Draw("pid.aoz()>>ha4(250, 1.9, 2.6)", a4, "same");
  // ((TH1F *)f->Get("ha4"))->SetFillColor(4);
  // etf->Draw("pid.aoz()>>ha5(250, 1.9, 2.6)", a5, "same");
  // ((TH1F *)f->Get("ha5"))->SetFillColor(5);

  c->Print("pt3.pdf");
  cout << "\033[36;1m" << cut << "\033[0m" << endl;
} // end pt
